package com.idna.wsconsumer.utils;

import java.io.*;
import java.util.Properties;

/**
 * A utility class providing helper functions
 * 
 * @author kan.sun
 *
 */
public class ApplicationUtilImpl implements ApplicationUtil
{
	public static final String PROP_PATH = "H:/MyCodeBase/wsdlconsumer/netidservice/resource/properties/services.properties";
	
	
	/* (non-Javadoc)
	 * @see net.icdpublishing.wsconsumer.utils.ApplicationUtil#readFile(java.lang.String)
	 */
	public String readFile(String path) throws FileNotFoundException, IOException
	{
		BufferedReader reader = new BufferedReader(new FileReader(path));
		String line = "";
		String fileContents = "";
		while((line=reader.readLine())!=null)
		{
			fileContents += line;
		}
		return fileContents.trim();
	}

	/* (non-Javadoc)
	 * @see net.icdpublishing.wsconsumer.utils.ApplicationUtil#loadProperty(java.lang.String)
	 */
	public Properties loadProperty(String path) throws FileNotFoundException, IOException
	{
		Properties prop = new Properties();
		if (path.toLowerCase().endsWith(".properties"))
			prop.load(new FileInputStream(path));
		else if (path.toLowerCase().endsWith(".xml"))
			prop.loadFromXML(new FileInputStream(path));
		return prop;
	}
}
